export default function generateUniqueRandomString(length = 6) {
  const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
  const uniqueChars = new Set()
  let result = ''

  if (length > chars.length) {
    throw new Error(
      'Requested length exceeds the number of unique characters available.'
    )
  }

  while (uniqueChars.size < length) {
    uniqueChars.add(chars[Math.floor(Math.random() * chars.length)])
  }

  for (let char of uniqueChars) {
    result += char
  }

  return result
}
